import random

user = {"99999999": {"name": "管理员", "password": 123456, "address": "中华人民共和国北京市昌平区珠江摩尔3号楼1单元1508", "balance": 100,
                     "bank": "中国农业银行"}}


def welcome():
    print("***********************\n"
          "*        农业银行       *\n"
          "***********************\n"
          "*        1. 开户       *\n"
          "*        2. 存钱       *\n"
          "*        3. 取钱       *\n"
          "*        4. 转账       *\n"
          "*        5. 查询       *\n"
          "*        6. 退出       *\n"
          "***********************"
          )


def account_judgment(account):
    if account in user:
        return 1
    else:
        return 0


def user_account():
    if len(user) <= 100:
        account = str(random.randint(10000000, 99999999))
        a = account_judgment(account)
        while a != 0:
            account = str(random.randint(10000000, 99999999))
        else:
            name = input("请输入您的姓名：")
            password = input("请输入您的密码：")
            p = password_six(password)
            if p == 1:
                country = input("请输入您的国籍！")
                province = input("请输入您户口所在的省份！")
                street = input("请输入您户口所在的街道！")
                door_number = input("请输入您户口所在的门牌号！")
                address = country + province + street + door_number
                balance = input("请输入您的余额：")
                bank = str("中国农业银行")
                user[account] = {"name": name, "password": password, "address": address, "balance": balance, "bank": bank}
                print_user_information(account)
                return 1
            else:
                return 2
    else:
        return 0


def print_user_information(account):
    print("以下是您的用户信息：")
    print("您的账号：", account)
    print("您的姓名：", user[account]['name'])
    print("您的密码：", "******")
    print("您的地址：", user[account]["address"])
    print("您的余额：", user[account]['balance'])
    print("您的开户行：", user[account]["bank"])


def user_account_info():
    a = user_account()
    if a == 1:
        print("添加用户成功！")
    elif a == 2:
        print("请注意！密码需要输入六位！")
    else:
        print("库满，请到本行的其他分行办理业务！")


def password_six(password):
    n = len(password)
    if n == 6:
        return 1
    else:
        return 0


def password_judgment(accounts, password):
    user[accounts]["password"] = str(user[accounts]["password"])
    if password != user[accounts]["password"]:
        return 1
    else:
        return 0


def save_money():
    accounts = input("请输入那您的账户：")
    a = account_judgment(accounts)
    if a == 1:
        password = input("请输入那您的密码：")
        user[accounts]["password"] = str(user[accounts]["password"])
        b = password_judgment(accounts, password)
        if b == 1:
            print("密码输入错误！")
        else:
            money = input("请输入您存入的金额：")
            u = int(user[accounts]["balance"])
            u += int(money)
            user[accounts]["balance"] = u
            print("账户余额：", user[accounts]["balance"], "元")
            print("存入成功！")
    else:
        print("账户输入错误！")


def money_judgement(money, account):
    user[account]["balance"] = str(user[account]["balance"])
    if money <= user[account]["balance"]:
        return 1
    else:
        return 0


def withdraw_cash():
    account = input("请输入您的账户：")
    a = account_judgment(account)
    if a == 1:
        password = input("请输入您的密码：")
        b = password_judgment(account, password)
        if b == 1:
            print("密码输入错误！")
        else:
            money = input("请输入您取出的金额：")
            u = int(user[account]["balance"])
            m = money_judgement(money, account)
            if m == 1:
                u -= int(money)
                user[account]["balance"] = u
                print("用户剩余金额：", u, "元")
                print("取钱成功！")
            else:
                print("您的余额不足！")


def transfer_account():
    account = input("请输入您的账户：")
    a = account_judgment(account)
    if a == 1:
        password = input("请输入您的密码：")
        b = password_judgment(account, password)
        if b == 1:
            print("密码输入错误！")
        else:
            accounts = input("请输入您转入的账户：")
            s = account_judgment(accounts)
            if s == 1:
                money = input("请输入您转出的金额：")
                u = int(user[account]["balance"])
                m = money_judgement(money, account)
                if m == 1:
                    u -= int(money)
                    user[account]["balance"] = u
                    user[accounts]["balance"] += int(money)
                    print("用户剩余金额：", u, "元")
                    print("转账成功！")
                else:
                    print("您的余额不足！")
            else:
                print("您转入的账户输入错误！")


def user_inquiry():
    account = input("请输入您所查询的账号：")
    a = account_judgment(account)
    if a == 1:
        password = input("请输入您的密码：")
        b = password_judgment(account, password)
        if b == 1:
            print("密码输入错误！")
        else:
            print_user_information(account)
    else:
        print("您转入的账户输入错误！")


while 1:
    welcome()
    choice = input("请选择您要办理的业务：")
    if choice == "1":
        user_account_info()
        pass
    elif choice == "2":
        save_money()
        pass
    elif choice == "3":
        withdraw_cash()
        pass
    elif choice == "4":
        transfer_account()
        pass
    elif choice == "5":
        user_inquiry()
        pass
